<template>
  <el-dialog :title="'修改状态'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="卡密状态" prop="status">
        <el-radio-group v-model="dataForm.status" size="small">
          <el-radio :label=0>修改为已卖出</el-radio>
          <el-radio :label=1>不修改</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="选择代理" prop="agentId">
        <el-select v-model="dataForm.agentId" style="width:100%" filterable placeholder="代理商">
           <el-option v-for="item in agentList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="推送添加" prop="agenticState">
        <el-radio-group v-model="dataForm.agenticState" size="small">
          <el-radio :label=0>添加</el-radio>
          <el-radio :label=1>不添加</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          status: 0,
          agentId: '',
          remark: '',
          agenticState: 0
        },
        ids: '',
        agentList: [],
        dataRule: {
          cdkeynum: [{
            required: true,
            message: '卡密不能为空',
            trigger: 'blur'
          }],
          cdkType: [{
            required: true,
            message: 'cdk类型',
            trigger: 'blur'
          }],
          cdkDateType: [{
            required: true,
            message: '卡密日期类型',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(ids, agentList) {
        this.ids = ids;
        this.agentList = agentList
        this.visible = true
        this.$refs['dataForm'].resetFields()
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/cards/amgcdkcards/updateWholesale`),
              method: 'post',
              params: this.$http.adornParams({
                'cdkeynum': this.dataForm.cdkeynum,
                'cdkType': this.dataForm.cdkType,
                'cdkDateType': this.dataForm.cdkDateType
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }

</script>
